<?php


namespace EleMe\OpenApi\Kernel;

use EleMe\OpenApi\Shop\Client as shopClient;
use EleMe\OpenApi\Order\Client as orderClient;

use EleMe\OpenApi\Base\Oauth\Client as authClient;
class Factory
{
    public $config = null;
    public $kernel = null;
    private static $instance;
    protected static $shop;
    protected static $baseAuth;
    protected static $order;

    private function __construct($config){
        $kernel = new EasySDKKernel($config);
        self::$shop = new Shop($kernel);
        self::$baseAuth = new BaseAuth($kernel);
        self::$order = new Order($kernel);
    }

    public static function setOptions($config)
    {
        if (!(self::$instance instanceof self)) {
            self::$instance = new self($config);
        }
        return self::$instance;
    }

    public static function shop()
    {
        return self::$shop;
    }
    public static function baseAuth()
    {
        return self::$baseAuth;
    }
    public static function order()
    {
        return self::$order;
    }

}
class Shop
{
    private $kernel;

    public function __construct($kernel)
    {
        $this->kernel = $kernel;
    }
    public function shop()
    {
        return new shopClient($this->kernel);
    }

}
class Order
{
    private $kernel;

    public function __construct($kernel)
    {
        $this->kernel = $kernel;
    }
    public function order()
    {
        return new orderClient($this->kernel);
    }

}
class BaseAuth
{
    private $kernel;

    public function __construct($kernel)
    {
        $this->kernel = $kernel;
    }
    public function baseAuth()
    {
        return new authClient($this->kernel);
    }

}